import os
import sys
sys.path.append(os.path.abspath('.'))

from xml.dom.minidom import parse
import cv2
import matplotlib.pyplot as plt
import numpy as np

import csv

'''
result
[2395.27527018 1896.47488875]
'''


f = open('./scripts/img_size_test_a.csv','w',encoding='utf-8')
csv_writer = csv.writer(f)

root_img_path='/home/hfle/data_dog/TEST_A'
# root_label_path='/home/hfle/data_dog/Low-Annotations'

total=list()
csv_writer.writerow(['No','file_name','img_height','img_width'])

for i,img_name in enumerate(os.listdir(root_img_path)):
    img_path=os.path.join(root_img_path,img_name)
    # label_path=os.path.join(root_label_path,c,img_name)+'.xml'

    if not (os.path.exists(img_path)):
        continue

    # 读取图片
    img = cv2.imread(img_path)
    img_height,img_width=img.shape[:2]

    total.append([img_height,img_width])
    csv_writer.writerow([str(i+1),img_name]+list(total[-1]))
    f.flush()
res=np.array(total)
avg_res=res.mean(axis=0)
print(avg_res)


